{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "cT5Nq-ef7_aq"
      },
      "source": [
        "## Get This repo"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "YlMlMVfuyHR7"
      },
      "outputs": [],
      "source": [
        "!pip install --upgrade setuptools pip --user\n",
        "!pip install nvidia-pyindex\n",
        "!pip install --upgrade nvidia-tensorrt\n",
        "!pip install pycuda"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "S6S5Vf_BzDXt"
      },
      "outputs": [],
      "source": [
        "!git clone https://github.com/Linaom1214/TensorRT-For-YOLO-Series.git"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "N-pKcEA0yKPu"
      },
      "outputs": [],
      "source": [
        "%cd TensorRT-For-YOLO-Series"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "KmC2JyO-6yJA"
      },
      "source": [
        "1. [YOLOv5](##YOLOv5)\n",
        "2. [YOLOx](##YOLOX)\n",
        "3. [YOLOv6](##YOLOV6)\n",
        "4. [YOLOv7](##YOLOv7)\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "wNn6pwwe8Kny"
      },
      "source": [
        "## YOLOv5"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "ykcT75aw4Y70"
      },
      "outputs": [],
      "source": [
        "!git clone https://github.com/ultralytics/yolov5.git"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "rGX9MZbV60kK"
      },
      "outputs": [],
      "source": [
        "!wget https://github.com/ultralytics/yolov5/releases/download/v6.1/yolov5n.pt"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "oya4Jr7o64B5"
      },
      "outputs": [],
      "source": [
        "!python yolov5/export.py --weights yolov5n.pt --include onnx --simplify --inplace "
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "gYvIPqSC6M26"
      },
      "source": [
        "### include  NMS Plugin"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "WTeQuMco7U9V"
      },
      "outputs": [],
      "source": [
        "!python export.py -o yolov5n.onnx -e yolov5n.trt --end2end"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "KxjNoG5-7VlN"
      },
      "outputs": [],
      "source": [
        "!python trt.py -e yolov5n.trt  -i src/1.jpg -o yolov5n-1.jpg --end2end "
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "PU5QOg_P6NKu"
      },
      "source": [
        "###  exclude NMS Plugin"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "8Dk-0myN6RkX"
      },
      "outputs": [],
      "source": [
        "!python export.py -o yolov5n.onnx -e yolov5n.trt "
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "55mqK5QW6RbO"
      },
      "outputs": [],
      "source": [
        "!python trt.py -e yolov5n.trt  -i src/1.jpg -o yolov5n-1.jpg "
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "uvYnmDef_ZMd"
      },
      "source": [
        "## YOLOX "
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "hTEwyEtY_dT_"
      },
      "outputs": [],
      "source": [
        "!git clone https://github.com/Megvii-BaseDetection/YOLOX.git"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "WSwIXNLNAKAS"
      },
      "outputs": [],
      "source": [
        "!wget https://github.com/Megvii-BaseDetection/YOLOX/releases/download/0.1.1rc0/yolox_s.pth"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "lrqVRrKbAn1G"
      },
      "outputs": [],
      "source": [
        "!cd YOLOX && pip3 install -v -e . --user"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "aU1eNfQMCdvX"
      },
      "outputs": [],
      "source": [
        "!cd YOLOX && python tools/export_onnx.py --output-name ../yolox_s.onnx -n yolox-s -c ../yolox_s.pth --decode_in_inference"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "pqifdPC96BIM"
      },
      "source": [
        "### include  NMS Plugin"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "rRdzxt38FYUH"
      },
      "outputs": [],
      "source": [
        "!python export.py -o yolox_s.onnx -e yolox_s.trt --end2end"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "_Hhi678oFYnc"
      },
      "outputs": [],
      "source": [
        "!python trt.py -e yolox_s.trt  -i src/1.jpg -o yolox-1.jpg --end2end "
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "8Su-zYr_6BhA"
      },
      "source": [
        "###  exclude NMS Plugin"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "HHjENMwc6Ft6"
      },
      "outputs": [],
      "source": [
        "!python export.py -o yolox_s.onnx -e yolox_s.trt "
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "AHJJt99C6Fjv"
      },
      "outputs": [],
      "source": [
        "!python trt.py -e yolox_s.trt  -i src/1.jpg -o yolox-1.jpg "
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "EN6zNI5d_bQO"
      },
      "source": [
        "## YOLOv6 "
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "zQgcqDQIJ9ZL"
      },
      "outputs": [],
      "source": [
        "!wget https://github.com/meituan/YOLOv6/releases/download/0.1.0/yolov6s.onnx"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "GeZMKC9D5Fkc"
      },
      "source": [
        "### include  NMS Plugin"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "avX1Da1hJ9Cn"
      },
      "outputs": [],
      "source": [
        "!python export.py -o yolov6s.onnx -e yolov6s.trt --end2end"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "8y7iS8dmKIRa"
      },
      "outputs": [],
      "source": [
        "!python trt.py -e yolov6s.trt  -i src/1.jpg -o yolov6s-1.jpg --end2end"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "PHpD2P6n5EqS"
      },
      "source": [
        "###  exclude NMS Plugin"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "hMncjMUu58SF"
      },
      "outputs": [],
      "source": [
        "!python export.py -o yolov6s.onnx -e yolov6s.trt "
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "bvwJM04H58ry"
      },
      "outputs": [],
      "source": [
        "!python trt.py -e yolov6s.trt  -i src/1.jpg -o yolov6s-1.jpg "
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "_a6qcc-T_VW0"
      },
      "source": [
        "## YOLOv7"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "yzbPxByeL2F4"
      },
      "outputs": [],
      "source": [
        "!git clone https://github.com/WongKinYiu/yolov7.git"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "oOWZ0AakL1-f"
      },
      "outputs": [],
      "source": [
        "!wget https://github.com/WongKinYiu/yolov7/releases/download/v0.1/yolov7-tiny.pt"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "g-TJOzcJL1wL"
      },
      "outputs": [],
      "source": [
        "!pip install -r yolov7/requirements.txt"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "ExRYUF9eL13x"
      },
      "outputs": [],
      "source": [
        "!python yolov7/export.py --weights yolov7-tiny.pt --grid  --simplify"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "0Y7Q_GxK3dgL"
      },
      "source": [
        "### include  NMS Plugin"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "uiiGI1e7wvft"
      },
      "outputs": [],
      "source": [
        "!python export.py -o yolov7-tiny.onnx -e yolov7-tiny.trt --end2end"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "V-BdioMnz-Xb"
      },
      "outputs": [],
      "source": [
        "!python trt.py -e yolov7-tiny.trt  -i src/1.jpg -o yolov7-tiny-1.jpg --end2end"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "yX2bt9aE3gzz"
      },
      "source": [
        "###  exclude NMS Plugin"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "lAH-ga73sg7T"
      },
      "outputs": [],
      "source": [
        "!python export.py -o yolov7-tiny.onnx -e yolov7-tiny-norm.trt"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "5Nw0Yus63wZb"
      },
      "outputs": [],
      "source": [
        "!python trt.py -e yolov7-tiny-norm.trt  -i src/1.jpg -o yolov7-tiny-norm-1.jpg"
      ]
    }
  ],
  "metadata": {
    "accelerator": "GPU",
    "colab": {
      "collapsed_sections": [],
      "name": "TensorRT.ipynb",
      "provenance": []
    },
    "gpuClass": "standard",
    "kernelspec": {
      "display_name": "Python 3.9.12 ('fps')",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.9.12"
    },
    "vscode": {
      "interpreter": {
        "hash": "bd0ce2edec774997c375a14df5f6bcd56e33a8a108489ca6d1f356b6a76190b6"
      }
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
